package com.util;


//使用 int2char 方法将整数转换为字符数组。
public class int2charUnit {
    public static void int2char(byte[] output, int input) {
        if (output.length < 4) {
            throw new IllegalArgumentException("Output array must have at least 4 elements.");
        }
        output[0] = (byte) ((input >> 24) & 0xFF);
        output[1] = (byte) ((input >> 16) & 0xFF);
        output[2] = (byte) ((input >> 8) & 0xFF);
        output[3] = (byte) (input & 0xFF);
    }

        // 假设实现字符数组的打印
        public static void strPrint(byte[] output) {
            char[] charArray = convertByteArrayToCharArray(output);
            printCharArray(charArray);
        }

    public static char[] convertByteArrayToCharArray(byte[] byteArray) {
        char[] charArray = new char[byteArray.length];
        for (int i = 0; i < byteArray.length; i++) {
            charArray[i] = (char) byteArray[i];
        }
        return charArray;
    }

    public static void printCharArray(char[] charArray) {
        for (char c : charArray) {
            System.out.print((int)c);
        }
        System.out.println();
    }


    public static void main(String[] args) {
        for (int i = 0; i < 4; i++) {
            int result = i;
            byte[] output = {65,66,67,68};
            int2char(output, result);
            strPrint(output);
            int test = Char2intUnit.char2int(output,i);
            System.out.println(test);
        }
    }

}
